package com.bt.lms.ui.page.school_education.stu_basic;

import com.bt.lms.ui.action.school_education.stu_basic.BasicMes.BasicMesEditAction;
import com.bt.lms.ui.action.school_education.stu_basic.familyMember.FamilyMemberAddAction;
import com.bt.lms.ui.action.school_education.stu_basic.familyMember.DeleteVerifyAction;
import com.bt.lms.ui.action.school_education.stu_basic.familyMember.FamilyMemberEditAction;
import com.bt.lms.ui.page.school_education.stu_mes_manage.PageStudentMesManage;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;

import java.util.ArrayList;
import java.util.List;

/**
 * 学员基本信息界面
 */
public class PageStudentBasicMes extends VBox {


    private final double baseWidth = 1230;

    private HBox one;

    public PageStudentBasicMes(PageStudentMesManage pageStudentMesManage) {
        this.setPrefWidth(1200);

        VBox totalVBox = new VBox();
        Insets insets = new Insets(10);
        totalVBox.setPadding(insets);
        totalVBox.setPrefWidth(1180);

        Label studentBasic = new Label("招生计划A-灭霸学员基本信息");
        studentBasic.setFont(Font.font("圆体", 20));
        totalVBox.getChildren().add(studentBasic);

        Label basicMes = new Label("基本信息");
        basicMes.setFont(Font.font("圆体", 20));
        HBox hBox1 = new HBox();
        hBox1.setPrefWidth(1200);
        hBox1.setStyle("-fx-background-color: #cec9c9");
        hBox1.getChildren().add(basicMes);
        totalVBox.getChildren().add(hBox1);


        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setPrefWidth(1200);
        //设置滚动盒子只有竖向
        scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);


        HBox editBox = new HBox();
        editBox.setPrefWidth(baseWidth);
        Insets insets1 = new Insets(10, 40, 10, 10);
        editBox.setPadding(insets1);
        editBox.setAlignment(Pos.CENTER_RIGHT);
        Button editBtn = new Button("💻编辑");
        editBox.getChildren().add(editBtn);
        totalVBox.getChildren().add(editBox);
        //按钮样式
        BtnStyle.saveBtn(editBtn);

        //变成小手
        editBox.setCursor(Cursor.HAND);
        //基本信息
        VBox basicVBox = initBasicInfo();

        totalVBox.getChildren().add(basicVBox);

        //编辑按钮事件
        BasicMesEditAction basicMesEditAction = new BasicMesEditAction(totalVBox, one, basicVBox);
        editBtn.setOnAction(basicMesEditAction);

        //初始化更多基本信息盒子
        initMoroMesBox(basicVBox);
        //初始化家庭成员信息盒子
        initFamilyMemberBox(totalVBox);

        scrollPane.setContent(totalVBox);
        this.getChildren().add(scrollPane);
    }

    /**
     * 初始化更多基本信息盒子
     *
     * @param totalVBox
     */
    private void initMoroMesBox(VBox totalVBox) {
        VBox vBox = new VBox();
        Insets insets = new Insets(10, 10, 10, 0);
        vBox.setPadding(insets);
        vBox.setSpacing(10);

        HBox totalHBox = new HBox();
        totalHBox.setPrefWidth(baseWidth);
        totalHBox.setSpacing(10);

        VBox one = new VBox();
        one.setPrefWidth(baseWidth / 8);
        one.setSpacing(10);
        Label studyTimeLab = new Label("英文姓名");
        Label studyCertifierLab = new Label("曾用名");
        Label acquireDegreeLab = new Label("国籍/地区");
        Label studyContentLab = new Label("健康状况");
        Label remarkLab = new Label("身份证有效期");
        one.getChildren().addAll(studyTimeLab, studyCertifierLab, acquireDegreeLab, studyContentLab, remarkLab);
        totalHBox.getChildren().add(one);

        VBox two = new VBox();
        two.setPrefWidth(baseWidth / 3);
        two.setSpacing(10);
        Label studyTimeMes = new Label("wang bo");
        Label studyCertifierMes = new Label("无");
        Label acquireDegreeMes = new Label("中国大陆");
        Label studyContentMes = new Label("健康");
        HBox hBox = new HBox();
        hBox.setPrefWidth(baseWidth/3);
        hBox.setSpacing(10);
        Label label = new Label("2020年5月1日");
        Label label1 = new Label("至");
        Label remarkMes = new Label("2032年10月1日");
        hBox.getChildren().addAll(label,label1,remarkMes);
        two.getChildren().addAll(studyTimeMes, studyCertifierMes, acquireDegreeMes, studyContentMes, hBox);
        totalHBox.getChildren().add(two);


        VBox three = new VBox();
        three.setPrefWidth(baseWidth / 8);
        three.setSpacing(10);
        Label studyUnitLab = new Label("姓名拼音");
        Label specialtyNameLab = new Label("信仰宗教");
        Label pecialtyNameLab = new Label("港澳太侨外");
        Label ecialtyNameLab = new Label("血型");
        Label cialtyNameLab = new Label("是否独生子女");
        three.getChildren().addAll(studyUnitLab, specialtyNameLab, pecialtyNameLab, ecialtyNameLab, cialtyNameLab);
        totalHBox.getChildren().add(three);

        VBox four = new VBox();
        four.setPrefWidth(baseWidth / 3);
        four.setSpacing(10);
        Label studyUnitMes = new Label("wangbo");
        Label specialtyNameMes = new Label("无");
        Label pecialtyNameMes = new Label("否");
        Label ecialtyNameMes = new Label("O型");
        Label cialtyNameMes = new Label("否");
        four.getChildren().addAll(studyUnitMes, specialtyNameMes, pecialtyNameMes, ecialtyNameMes, cialtyNameMes);
        totalHBox.getChildren().add(four);
        //把信息加入信息的主盒子
        vBox.getChildren().add(totalHBox);

        Accordion accordion = new Accordion();
        accordion.setMaxWidth(1100);
        TitledPane titledPane = new TitledPane("更多基本信息", null);
        titledPane.setContent(vBox);
        accordion.getPanes().add(titledPane);
        totalVBox.getChildren().add(accordion);


    }

    /**
     * 初始化家庭成员信息盒子
     *
     * @param totalVBox 主盒子
     */
    private void initFamilyMemberBox(VBox totalVBox) {
        VBox vBox = new VBox();
        Insets insets = new Insets(10, 10, 10, 0);
        vBox.setPadding(insets);
        Label basicMes = new Label("家庭成员");
        HBox hBox1 = new HBox();
        hBox1.setPrefWidth(1280);
        hBox1.setStyle("-fx-background-color: #cec9c9");
        hBox1.getChildren().add(basicMes);
        basicMes.setFont(Font.font("圆体", 20));
        vBox.getChildren().add(hBox1);
        vBox.setSpacing(10);


        HBox hBox = new HBox();
        hBox.setPrefWidth(baseWidth);
        hBox.setAlignment(Pos.CENTER_RIGHT);
        hBox.setSpacing(10);
        Insets insets1 = new Insets(10, 30, 10, 10);
        hBox.setPadding(insets1);
        Button editBtn = new Button("💻编辑");
        Button deleteBtn = new Button("❌删除");
        hBox.getChildren().add(editBtn);
        hBox.getChildren().add(deleteBtn);
        //按钮样式
        BtnStyle.saveBtn(editBtn);
        BtnStyle.cancelBtn(deleteBtn);
        editBtn.setCursor(Cursor.HAND);
        deleteBtn.setCursor(Cursor.HAND);


        List<VBox> list = new ArrayList<>();
        VBox vBox1 = new VBox();

        //初始化家庭成员盒子
        HBox totalHBox = initFamilyMember();
        vBox1.getChildren().addAll(hBox,totalHBox);
        vBox.getChildren().add(vBox1);
        list.add(vBox1);

        deleteBtn.setOnAction(event -> {
            Alert alert = new Alert(Alert.AlertType.NONE);
            alert.setHeaderText(null);
            alert.setTitle("删除");
            DeleteVerifyAction deleteVerifyAction = new DeleteVerifyAction(alert,vBox,list);
            deleteVerifyAction.handle();
            alert.getDialogPane().setPrefWidth(500);
            alert.getDialogPane().setPrefHeight(300);
            alert.setGraphic(deleteVerifyAction);
            alert.showAndWait();
        });

        //事件
        FamilyMemberEditAction familyMemberEditAction = new FamilyMemberEditAction(vBox,list,totalHBox);
        editBtn.setOnAction(familyMemberEditAction);

        HBox continueBox = new HBox();
        continueBox.setPrefWidth(1280);
        continueBox.setPadding(new Insets(10));
        Button addBtn = new Button("继续添加");
        BtnStyle.addBtn(addBtn);
        continueBox.getChildren().add(addBtn);

        //事件
        FamilyMemberAddAction familyMemberAddAction = new FamilyMemberAddAction(vBox,list,totalHBox);
        addBtn.setOnAction(familyMemberAddAction);
        //变成小手
        addBtn.setCursor(Cursor.HAND);



        totalVBox.getChildren().add(vBox);
        totalVBox.getChildren().add(continueBox);

    }


    /**
     * 基本信息
     * @return 基本信息盒子
     */
    public VBox initBasicInfo(){
        VBox vBox = new VBox();
        //基本信息的主盒子
        one = new HBox();
        one.setPrefWidth(baseWidth);
        one.setSpacing(10);

        VBox two = new VBox();
        double hBoxWidth = 1230 - 300;
        two.setPrefWidth(hBoxWidth / 8);
        two.setSpacing(10);
        Label numberLab = new Label("学员编号");
        Label sexLab = new Label("性别");
        Label nativeLab = new Label("籍贯");
        Label birthPlaceLab = new Label("出生地");
        Label IDTypeLab = new Label("证件类型");
        Label maritalStatusLab = new Label("婚姻状况");

        two.getChildren().addAll(numberLab, sexLab, nativeLab, birthPlaceLab, IDTypeLab, maritalStatusLab);
        one.getChildren().add(two);

        VBox three = new VBox();
        three.setPrefWidth(hBoxWidth / 3);
        three.setSpacing(10);
        Label numberMes = new Label("202301");
        Label sexMes = new Label("男");
        Label nativeMes = new Label("北京");
        Label birthPlaceMes = new Label("山西省晋城市陵川县");
        Label IDTypeMes = new Label("身份证");
        Label maritalStatusMes = new Label("未婚");
        three.getChildren().addAll(numberMes, sexMes, nativeMes, birthPlaceMes, IDTypeMes, maritalStatusMes);
        one.getChildren().add(three);


        VBox four = new VBox();
        four.setPrefWidth(hBoxWidth / 8);
        four.setSpacing(10);
        Label nameLab = new Label("姓名");
        Label birthdayLab = new Label("出生日期");
        Label nationLab = new Label("民族");
        Label Lab = new Label();
        Label IDNumberLab = new Label("证件号码");
        Label politicsStatusLab = new Label("政治面貌");
        four.getChildren().addAll(nameLab, birthdayLab, nationLab, Lab, IDNumberLab, politicsStatusLab);
        one.getChildren().add(four);

        VBox five = new VBox();
        five.setPrefWidth(hBoxWidth / 3);
        five.setSpacing(10);
        Label nameMes = new Label("灭霸");
        Label birthdayMes = new Label("2001-12-29");
        Label nationMes = new Label("汉");
        Label labMes = new Label();
        Label IDNumberMes = new Label("140524200112290010");
        Label politicsStatusMes = new Label("团员");
        five.getChildren().addAll(nameMes, birthdayMes, nationMes, labMes, IDNumberMes, politicsStatusMes);
        one.getChildren().add(five);

        VBox six = new VBox();
        six.setPrefWidth(300);
        Pane pane = new Pane();
        pane.setPrefHeight(100);
        pane.setMaxWidth(100);
        String url = "file:\\C:\\Users\\Administrator\\Pictures\\Saved Pictures\\666.jpeg";
        Image image = new Image(url);
        ImageView imageView = new ImageView(image);
        imageView.setFitWidth(100);
        imageView.setFitHeight(100);
        pane.getChildren().add(imageView);
        six.getChildren().add(pane);
        one.getChildren().add(six);
        vBox.getChildren().add(one);


        return vBox;
    }


    /**
     * 家庭成员信息盒子
     * @return 盒子
     */
    public HBox initFamilyMember(){
        //家庭成员信息的主盒子
        HBox totalHBox = new HBox();
        totalHBox.setPrefWidth(baseWidth);
        totalHBox.setSpacing(10);

        VBox one1 = new VBox();
        one1.setPrefWidth(baseWidth / 8);
        one1.setSpacing(10);
        Label relationLab = new Label("关系");
        Label jobUnitLab = new Label("成员工作单位");
        Label nationLab = new Label("民族");
        Label professionalSkillLab = new Label("专业技术职务");
        Label isEmergencyContact = new Label("是否紧急联系人");
        one1.getChildren().addAll(relationLab, jobUnitLab, nationLab, professionalSkillLab,isEmergencyContact);
        totalHBox.getChildren().add(one1);

        VBox one2 = new VBox();
        one2.setPrefWidth(baseWidth / 6);
        one2.setSpacing(10);
        Label relationMes = new Label("父亲");
        relationMes.setId("relationMes");
        Label jobUnitLabMes = new Label();
        jobUnitLabMes.setId("jobUnitLabMes");
        Label nationMes = new Label("汉族");
        nationMes.setId("nationMes");
        Label professionalSkillLabMes = new Label("无");
        professionalSkillLabMes.setId("professionalSkillLabMes");
        Label isLab = new Label("是");
        isLab.setId("isLab");
        one2.getChildren().addAll(relationMes, jobUnitLabMes, nationMes, professionalSkillLabMes,isLab);
        totalHBox.getChildren().add(one2);


        VBox one3 = new VBox();
        one3.setPrefWidth(baseWidth / 8);
        one3.setSpacing(10);
        Label memberNameLab = new Label("成员姓名");
        Label practitionersLab = new Label("从业");
        Label nationalityLab = new Label("国籍/地区");
        Label jobRankLab = new Label("职务级别");
        one3.getChildren().addAll(memberNameLab, practitionersLab, nationalityLab, jobRankLab);
        totalHBox.getChildren().add(one3);

        VBox one4 = new VBox();
        one4.setPrefWidth(baseWidth / 6);
        one4.setSpacing(10);
        Label memberNameLabMes = new Label("王波");
        memberNameLabMes.setId("memberNameLabMes");
        Label practitionersLabMes = new Label("干部");
        practitionersLabMes.setId("practitionersLabMes");
        Label nationalityMes = new Label("中国大陆");
        nationalityMes.setId("nationalityMes");
        Label jobRankLabMes = new Label("打工人");
        jobRankLabMes.setId("jobRankLabMes");
        one4.getChildren().addAll(memberNameLabMes, practitionersLabMes, nationalityMes, jobRankLabMes);
        totalHBox.getChildren().add(one4);


        VBox one5 = new VBox();
        one5.setPrefWidth(baseWidth / 8);
        one5.setSpacing(10);
        Label birthDataLab = new Label("出生年月");
        Label phoneLab = new Label("电话");
        Label healthConditionLab = new Label("健康状况");
        Label emileLab = new Label("电子邮箱");
        one5.getChildren().addAll(birthDataLab, phoneLab, healthConditionLab, emileLab);
        totalHBox.getChildren().add(one5);

        VBox one6 = new VBox();
        one6.setPrefWidth(baseWidth / 6);
        one6.setSpacing(10);
        Label birthDataLabMes = new Label("2001-12-29");
        birthDataLabMes.setId("birthDataLabMes");
        Label phoneLabMes = new Label("18834364327");
        phoneLabMes.setId("phoneLabMes");
        Label healthConditionLabMes = new Label("健康");
        healthConditionLabMes.setId("healthConditionLabMes");
        Label emileLabMes = new Label("1747381387@qq.com");
        emileLabMes.setId("emileLabMes");
        one6.getChildren().addAll(birthDataLabMes, phoneLabMes, healthConditionLabMes, emileLabMes);
        totalHBox.getChildren().add(one6);

        return totalHBox;
    }
}



